package com.liuya.page;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.math.RandomUtils;

public class ResponseData implements Serializable{
    private String page ;
    private String templet;
    private List<?> dataList ;
    private long docNum ;
    private int total ; 		//database data
    private String error ;
    private String message ;	//正常提示信息
    private boolean throwError = true;
    private Object data ;
    private List<?> valueList ;
    private Map values ;
    private Throwable ex ;
    private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH") ;
    private static SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyyMMdd") ;
    private static SimpleDateFormat toFormat = new SimpleDateFormat("dd'日'HH'时'") ;
    private static SimpleDateFormat toFormat2 = new SimpleDateFormat("dd'日'") ;

    public ResponseData( String templet  , String page){
        this.page = page;
        this.templet = templet ;
    }

    public ResponseData(String page , List<?> dataList){
        this.page = page;
        this.dataList = dataList ;
    }

    public ResponseData(String page , Object data){
        this.page = page;
        this.data = data ;
    }

    public ResponseData(String page , String error , boolean showError, Object data){
        this.page = page;
        this.error = error ;
        this.data = data ;
    }

    public ResponseData(String page){
        this.page = page ;
    }

    public ResponseData(String page , Throwable ex){
        this.page = page ;
        this.ex = ex ;
    }
    public double sin(int i , float r , float x ){
        double ci = Math.sqrt(Math.sqrt(r)) ;
        return Math.sin((Math.PI/180) * i)*(ci*x);
    }
    public double random(){
        return RandomUtils.nextInt(360) ;
    }
    public double cos(int i , float r, float x){
        return Math.cos((Math.PI/180) * i)*(Math.sqrt(Math.sqrt(r))*x);
    }

    public String convertDate(String datestr  , int r){
        String value ;
        try {
            if(r<=1){
                value = toFormat.format(dateFormat.parse(datestr)) ;
            }else if(r>=2){
                value = toFormat2.format(dateFormat2.parse(datestr)) ;
            }else{
                value = String.valueOf(datestr) ;
            }
        } catch (ParseException e) {
            e.printStackTrace();
            value = String.valueOf(datestr) ;
        }
        return value ;
    }

    public String replace(String value){
        return value.replaceAll("\\pP|\\pS", "") ;
    }
    public String getPage() {
        return page;
    }
    public void setPage(String page) {
        this.page = page;
    }
    public List<?> getDataList() {
        return dataList;
    }
    public void setDataList(List<?> dataList) {
        this.dataList = dataList;
    }
    public String getTemplet() {
        return templet;
    }

    public void setTemplet(String templet) {
        this.templet = templet;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public long getDocNum() {
        return docNum;
    }

    public void setDocNum(long docNum) {
        this.docNum = docNum;
    }

    public List<?> getValueList() {
        return valueList;
    }

    public void setValueList(List<?> valueList) {
        this.valueList = valueList;
    }

    public Map getValues() {
        return values;
    }

    public void setValues(Map values) {
        this.values = values;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public boolean isThrowError() {
        return throwError;
    }

    public void setThrowError(boolean throwError) {
        this.throwError = throwError;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Throwable getEx() {
        return ex;
    }

    public void setEx(Throwable ex) {
        this.ex = ex;
    }

}
